<?php
class Zendvn_View_Helper_CmsUrl extends Zend_View_Helper_Url{
	
	public function cmsUrl($urlOptions = array(), $route = null, $map = array(), $reset = false, $encode = true){
		
		
		$front = Zend_Controller_Front::getInstance();
        $request = $front->getRequest();
        $router = $front->getRouter();
        
	  	if (($urlOptions['action'])==null) {      
            $urlOptions['action'] =  $request->getActionName();
        }
        if (empty($urlOptions['controller'])){
             $urlOptions['controller'] = $request->getControllerName();
        }
        if (empty($urlOptions['module'])) {
            $urlOptions['module'] = $request->getModuleName();;
        }
        
        
       $params = $request->getParams();
       
       if(count($map)>0){
       		$mapArr = array();
       		foreach ($map as $key => $val){     
       			if(!empty($params[$val]))  {		
        			$mapArr[$val] = $params[$val];  
       			}     		
        	}
        	$urlOptions = array_merge($mapArr,$urlOptions);
        }
        
        if(!$router->hasRoute($route) || $route === null || ZENDVN_ROUTER != true){
        	$route = 'default';
        	$reset = true;      
			
        }
        if(ROUTER==false) return $this->url($urlOptions, 'default', $reset,$encode);
        return $this->url($urlOptions, $route, $reset,$encode);
	}
}